package pres.liko.iot.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pres.liko.iot.bean.R;
import pres.liko.iot.user.pojo.Dc3User;
import pres.liko.iot.user.pojo.UserToken;
import pres.liko.iot.user.service.UserService;
import reactor.core.publisher.Mono;

/**
 * @ClassName: UserController
 * @Auther: liko
 * @Description:
 * @Date: 2022/11/3 20:12
 */
@RestController
@RequestMapping("/user")
public class UserController {

    private UserService userService;

    @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }


    @PostMapping("/info")
    public Mono<R<Object>> addUser(@RequestBody Mono<Dc3User> dc3UserMono) {
        return userService.addUser(dc3UserMono);
    }

    @PostMapping("/login/{nameOrPhoneOrEmail}/{password}")
    public Mono<R<UserToken>> login(@PathVariable String nameOrPhoneOrEmail, @PathVariable String password) {
        return userService.selByName(nameOrPhoneOrEmail, password);
    }
}
